package com.qiuzhiyi.fragment;

import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

import com.qiuzhiyi.R;
import com.qiuzhiyi.base.QZYBaseFragment;
import com.qiuzhiyi.net.ObservableHelper;
import com.qiuzhiyi.net.RetrofitHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Author: Li
 * Date: 2017/11/14 0014
 * Description: 提问列表
 */

public class QuestionListFragment extends QZYBaseFragment {


    @BindView(R.id.txt)
    TextView mTextView;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_question_list;
    }

    @Override
    protected void initSth() {
        super.initSth();
        mTextView.setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        getQuizList(mUid);
    }

    private void getQuizList(String humanId) {
        Map<String, String> map = new HashMap<>();
        map.put("humanId", humanId);
        ObservableHelper.createObservable(RetrofitHelper.createService().getQuizList(map))
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                        showLoadingDialog();
                    }

                    @Override
                    public void onNext(String s) {
                        mTextView.setText(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        dismissLoadingDialog();
                    }

                    @Override
                    public void onComplete() {
                        dismissLoadingDialog();
                    }
                });
    }
}
